home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / Filezilla Server / FileZilla_Server-0_9_41.exe / source / version.cpp < prev    next >
C/C++ Source or Header  |  2011-11-06  |  4KB  |  127 lines

  1. // FileZilla Server - a Windows ftp server
  2.  
  3. // Copyright (C) 2002-2004 - Tim Kosse <tim.kosse@gmx.de>
  4.  
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9.  
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. #include "stdafx.h"
  20. #include "version.h"
  21.  
  22. CStdString GetVersionString()
  23. {
  24.     //Fill the version info
  25.     TCHAR fullpath[MAX_PATH + 10];
  26.     GetModuleFileName(0, fullpath, MAX_PATH + 10);
  27.     
  28.     TCHAR *str = new TCHAR[_tcslen(fullpath) + 1];
  29.     _tcscpy(str, fullpath);
  30.     DWORD tmp = 0;
  31.     DWORD len = GetFileVersionInfoSize(str, &tmp);
  32.     LPVOID pBlock = new char[len];
  33.     GetFileVersionInfo(str, 0, len, pBlock);
  34.     LPVOID ptr;
  35.     UINT ptrlen;
  36.  
  37.     CStdString ProductName;
  38.     //Retreive the product name
  39.     
  40.     TCHAR SubBlock[50];
  41.             
  42.     // Structure used to store enumerated languages and code pages.
  43.     struct LANGANDCODEPAGE {
  44.         WORD wLanguage;
  45.         WORD wCodePage;
  46.     } *lpTranslate;
  47.  
  48.     UINT cbTranslate;
  49.             
  50.     // Read the list of languages and code pages.
  51.     if (VerQueryValue(pBlock, 
  52.                 _T("\\VarFileInfo\\Translation"),
  53.                 (LPVOID*)&lpTranslate,
  54.                 &cbTranslate))
  55.     {
  56.         // Read the file description for each language and code page.
  57.     
  58.         _stprintf( SubBlock, 
  59.                _T("\\StringFileInfo\\%04x%04x\\ProductName"),
  60.                lpTranslate[0].wLanguage,
  61.                lpTranslate[0].wCodePage);
  62.         // Retrieve file description for language and code page "0". 
  63.         if (VerQueryValue(pBlock, 
  64.                 SubBlock, 
  65.                 &ptr, 
  66.                     &ptrlen))
  67.         {
  68.             ProductName = (TCHAR*)ptr;
  69.         }
  70.     }
  71.     CStdString version;
  72.     //Format the versionstring
  73.     if (VerQueryValue(pBlock, _T("\\"), &ptr, &ptrlen))
  74.     {
  75.         VS_FIXEDFILEINFO *fi = (VS_FIXEDFILEINFO*)ptr;
  76.         
  77.         if (fi->dwFileVersionMS >> 16)
  78.         {
  79.             //v1.00+
  80.             if (fi->dwFileVersionLS & 0xFFFF)
  81.             { //test releases
  82.                 if (fi->dwFileVersionLS >> 16)
  83.                 {
  84.                     TCHAR ch = 'a';
  85.                     ch += static_cast<TCHAR>(fi->dwFileVersionLS >> 16) - 1;
  86.                     version.Format(_T("%s version %d.%d%c test release %d)"), (LPCTSTR)ProductName, fi->dwFileVersionMS >> 16, fi->dwFileVersionMS & 0xFFFF, ch, fi->dwFileVersionLS & 0xFFFF);
  87.                 }
  88.                 else
  89.                     version.Format(_T("%s version %d.%d test release %d"), (LPCTSTR)ProductName, fi->dwFileVersionMS >> 16, fi->dwFileVersionMS & 0xFFFF, fi->dwFileVersionLS & 0xFFFF);
  90.             }
  91.             else
  92.             { //final versions
  93.                 if (fi->dwFileVersionLS >> 16)
  94.                 {
  95.                     TCHAR ch = 'a';
  96.                     ch += static_cast<TCHAR>(fi->dwFileVersionLS >> 16) - 1;
  97.                     version.Format(_T("%s version %d.%d%c final"), (LPCTSTR)ProductName, fi->dwFileVersionMS >> 16, fi->dwFileVersionMS & 0xFFFF, ch);
  98.                 }
  99.                 else
  100.                     version.Format(_T("%s version %d.%d final"), (LPCTSTR)ProductName, fi->dwFileVersionMS >> 16, fi->dwFileVersionMS & 0xFFFF);
  101.             }
  102.         }
  103.         else
  104.         {
  105.             //beta versions
  106.             if ((fi->dwFileVersionLS & 0xFFFF) / 100)
  107.                 if ((fi->dwFileVersionLS & 0xFFFF) % 100)
  108.                     //test release
  109.                     version.Format(_T("%s version 0.%d.%d%c beta test release %d"), (LPCTSTR)ProductName, fi->dwFileVersionMS & 0xFFFF, fi->dwFileVersionLS >> 16, (fi->dwFileVersionLS & 0xFFFF) / 100 + 'a' - 1, (fi->dwFileVersionLS & 0xFFFF) % 100);
  110.                 else
  111.                     //final version
  112.                     version.Format(_T("%s version 0.%d.%d%c beta"), (LPCTSTR)ProductName, fi->dwFileVersionMS & 0xFFFF, fi->dwFileVersionLS>>16, (fi->dwFileVersionLS & 0xFFFF) / 100 + 'a' - 1);
  113.             else
  114.                 if (fi->dwFileVersionLS&0xFFFF)
  115.                     //test release
  116.                     version.Format(_T("%s version 0.%d.%d beta test release %d"), (LPCTSTR)ProductName, fi->dwFileVersionMS & 0xFFFF, fi->dwFileVersionLS >> 16, fi->dwFileVersionLS & 0xFFFF);
  117.                 else
  118.                     //final version
  119.                     version.Format(_T("%s version 0.%d.%d beta"), (LPCTSTR)ProductName, fi->dwFileVersionMS&0xFFFF, fi->dwFileVersionLS >> 16);
  120.         }
  121.         
  122.     }
  123.     delete [] str;
  124.     delete [] pBlock;
  125.     return version;
  126. }
  127.